<?php

/****************************************
 *
 *  Author : Miguel Vasquez
 *  File   : userController.php
 *  Class userController
 *
 *  This class has the function of controlling the following pages:
 *  * Page main User
 *  * Favorites
 *  * Followers
 *  * Following
 *  * Media
 *  * Status
 *  * post
 *
 **************************************/

class userController extends Controller
{
    public function index() {

        $output                  = $this->loadModel('User');
        //update profile
        if(isset($_POST)){
            $this->updateProfile($_POST,$output);

            //update avatar
            if ($_FILES["pAvatar"]["error"] > 0) {
            } else {
                move_uploaded_file($_FILES["pAvatar"]["tmp_name"],
                    "public/avatar/" . $_FILES["pAvatar"]["name"]);
                $output->updateProfileAvatar(array('avatar'=>$_FILES["pAvatar"]["name"],'id'=>$_POST['pId']));
            }
            //end update avatar
            if(isset($_POST['pPass']) && $_POST['pPass'] != ''){
                $output->updateProfilePassword(array('id'=>$_POST['pId'],'password'=>$_POST['pPass']));
            }
        }
        //end update profile
        $this->_view->category = $output->getAllCategory();
		$this->_view->settings   = $output->getSettings();
        $this->_view->data       = $output->getUserId( $_GET['usr'] );
		$this->_view->notiMsg    = $output->notificationsMessages();
		$this->_view->notiIntera = $output->notificationsInteractions();
		$this->_view->_count     = count( $this->_view->data );
		$this->_view->pagesGeneral = $output->getAllPagesGeneral();
		$this->_view->getCountryUser = $output->getCountryUser( $this->_view->data[0]['id'] );
        $this->_view->countVote = $output->countVote($this->_view->data[0]['id']);
		//<---- Data User
		if( $this->_view->_count != 0 ) {
			$this->_view->title = stripslashes( $this->_view->data[0]['name'] )." @".$this->_view->data[0]['username']." ";
			$this->_view->titleH4 =  $_SESSION['LANG']['posts'];

			//<----- ALL POST INDEX PAGE
		   $this->_view->posts = $output->getAllPosts(
		   'WHERE P.user = '.$this->_view->data[0]['id'].'
			&& P.status = "1"
			&& P.status_general = "1"
			&& U.status = "active"
			GROUP BY P.id DESC', null , $this->_view->data[0]['id']
		   );

		//<<<<<----- ALL Followers PAGE
		   $this->_view->_getFollowers = $output->getFollowers(
		   'WHERE F.following = '. $this->_view->data[0]['id'] .' ', null , $this->_view->data[0]['id']
		   );

		   //<----- ALL POST FAVORITE PAGE
		   $this->_view->postsFavs = $output->getPostsFavs(
		   'WHERE F.id_usr = '. $this->_view->data[0]['id'] .' ', null , null
		   );

		   //<<<<<----- ALL Followers PAGE
		   $this->_view->_getFollowing = $output->getFollowing(
		   'WHERE F.follower = '. $this->_view->data[0]['id'] .' ', null , $this->_view->data[0]['id']
		   );
		   //<--- INFO USER SESSION ACTIVE
		   $this->_view->infoSession  = $output->infoUser( $_SESSION['authenticated'] );

		 //<--- INFO USER ALL
		   $this->_view->info  = $output->infoUser( $this->_view->data[0]['id'] );

		   //<--- WHO TO FOLLOWER
		   $this->_view->whoToFollow  = $output->whoToFollow( $_SESSION['authenticated'] );

		   //<--- TRENDING TOPIC
		   $this->_view->trending     = $output->getTrendsTopic();

		   //<-- Follower -> Following
		   $this->_view->followActive = $output->checkFollow( $this->_view->data[0]['id'],  $_SESSION['authenticated']);

		   //<-- Following -> Follower
		   $this->_view->followingActive = $output->checkFollow( $_SESSION['authenticated'], $this->_view->data[0]['id'] );

		   //<--- Show Last Photos
		   $this->_view->lastPhotosVideos = $output->getPhotosVideos( $this->_view->data[0]['id'] );

		   $this->_view->checkBlock  = $output->checkUserBlock( $_SESSION['authenticated'], $this->_view->data[0]['id'] );

		   $this->_view->checkBlocked  = $output->checkUserBlock( $this->_view->data[0]['id'], $_SESSION['authenticated'] );

			//<<<--- * File Ajax * --->>>
			$this->_view->_file  = 'get_posts.php';

		 }//<--- IF COUNT != 0

		 /* Show Views */
        //cusads
        $this->_view->addRight = $output->getAds('right');
        $this->_view->addleft = $output->getAds('left');
         $this->_view->render('profile', null );
    }

	public function favorites() {
    	$output                  = $this->loadModel('User');
        //update profile
        if(isset($_POST)){
            $this->updateProfile($_POST,$output);

            //update avatar
            if ($_FILES["pAvatar"]["error"] > 0) {
            } else {
                move_uploaded_file($_FILES["pAvatar"]["tmp_name"],
                    "public/avatar/" . $_FILES["pAvatar"]["name"]);
                $output->updateProfileAvatar(array('avatar'=>$_FILES["pAvatar"]["name"],'id'=>$_POST['pId']));
            }
            //end update avatar
            if(isset($_POST['pPass']) && $_POST['pPass'] != ''){
                $output->updateProfilePassword(array('id'=>$_POST['pId'],'password'=>$_POST['pPass']));
            }
        }
        //end update profile
        $this->_view->category = $output->getAllCategory();
        $this->_view->data       = $output->getUserId( $_GET['usr'] );
		$this->_view->settings   = $output->getSettings();
		$this->_view->notiMsg    = $output->notificationsMessages();
		$this->_view->notiIntera = $output->notificationsInteractions();
		$this->_view->_count     = count( $this->_view->data );
		$this->_view->pagesGeneral = $output->getAllPagesGeneral();
		$this->_view->getCountryUser = $output->getCountryUser( $this->_view->data[0]['id'] );
        $this->_view->countVote = $output->countVote($this->_view->data[0]['id']);
		//<---- Data User
		if( $this->_view->_count != 0 ) {
			$this->_view->title =  $_SESSION['LANG']['favorites'].' - '.stripslashes( $this->_view->data[0]['name'] )." @".$this->_view->data[0]['username']." ";
			$this->_view->titleH4 = $_SESSION['LANG']['favorites'];

			//<----- ALL POST INDEX PAGE
		   $this->_view->posts = $output->getAllPosts(
		   'WHERE P.user = '.$this->_view->data[0]['id'].'
		    && P.status_general = "1"
			&& P.status = "1"
			&& U.status = "active"
			GROUP BY P.id DESC ', null , $this->_view->data[0]['id']
		   );

			//<----- ALL POST FAVORITE PAGE
		   $this->_view->postsFavs = $output->getPostsFavs(
		   'WHERE F.id_usr = '. $this->_view->data[0]['id'] .' ', null , null
		   );

		//<<<<<----- ALL Followers PAGE
		   $this->_view->_getFollowers = $output->getFollowers(
		   'WHERE F.following = '. $this->_view->data[0]['id'] .' ', null , $this->_view->data[0]['id']
		   );

		   //<<<<<----- ALL Followers PAGE
		   $this->_view->_getFollowing = $output->getFollowing(
		   'WHERE F.follower = '. $this->_view->data[0]['id'] .' ', null , $this->_view->data[0]['id']
		   );
		   //<--- INFO USER SESSION ACTIVE
		   $this->_view->infoSession  = $output->infoUser( $_SESSION['authenticated'] );

		 //<--- INFO USER ALL
		   $this->_view->info  = $output->infoUser( $this->_view->data[0]['id'] );

		   //<--- WHO TO FOLLOWER
		   $this->_view->whoToFollow  = $output->whoToFollow( $_SESSION['authenticated'] );

		   //<--- TRENDING TOPIC
		   $this->_view->trending     = $output->getTrendsTopic();

		   //<-- Follower -> Following
		   $this->_view->followActive = $output->checkFollow( $this->_view->data[0]['id'],  $_SESSION['authenticated']);

		   //<-- Following -> Follower
		   $this->_view->followingActive = $output->checkFollow( $_SESSION['authenticated'], $this->_view->data[0]['id'] );

		   //<--- Show Last Photos
		   $this->_view->lastPhotosVideos = $output->getPhotosVideos( $this->_view->data[0]['id'] );

		   $this->_view->checkBlock  = $output->checkUserBlock( $_SESSION['authenticated'], $this->_view->data[0]['id'] );

		   $this->_view->checkBlocked  = $output->checkUserBlock( $this->_view->data[0]['id'], $_SESSION['authenticated'] );

			//<<<--- * File Ajax * --->>>
			$this->_view->_file  = 'get_posts_favorites.php';

		 }//<--- IF COUNT != 0

		 /* Show Views */
        //cusads
        $this->_view->addRight = $output->getAds('right');
        $this->_view->addleft = $output->getAds('left');
         $this->_view->render('profile', null );
    }

	public function followers() {
        $output                  = $this->loadModel('User');
        //update profile
        if(isset($_POST)){
            $this->updateProfile($_POST,$output);

            //update avatar
            if ($_FILES["pAvatar"]["error"] > 0) {
            } else {
                move_uploaded_file($_FILES["pAvatar"]["tmp_name"],
                    "public/avatar/" . $_FILES["pAvatar"]["name"]);
                $output->updateProfileAvatar(array('avatar'=>$_FILES["pAvatar"]["name"],'id'=>$_POST['pId']));
            }
            //end update avatar
            if(isset($_POST['pPass']) && $_POST['pPass'] != ''){
                $output->updateProfilePassword(array('id'=>$_POST['pId'],'password'=>$_POST['pPass']));
            }
        }
        //end update profile
        $this->_view->category = $output->getAllCategory();
        $this->_view->data       = $output->getUserId( $_GET['usr'] );
		$this->_view->settings   = $output->getSettings();
		$this->_view->notiMsg    = $output->notificationsMessages();
		$this->_view->notiIntera = $output->notificationsInteractions();
		$this->_view->_count     = count( $this->_view->data );
		$this->_view->pagesGeneral = $output->getAllPagesGeneral();
		$this->_view->getCountryUser = $output->getCountryUser( $this->_view->data[0]['id'] );
        $this->_view->countVote = $output->countVote($this->_view->data[0]['id']);
		//<---- Data User
		if( $this->_view->_count != 0 ) {
			$this->_view->title = $_SESSION['LANG']['followers'].' - '.stripslashes( $this->_view->data[0]['name'] )." @".$this->_view->data[0]['username']." ";
			$this->_view->titleH4 = $_SESSION['LANG']['followers'];

			//<----- ALL POST INDEX PAGE
		   $this->_view->posts = $output->getAllPosts(
		   'WHERE P.user = '.$this->_view->data[0]['id'].'
			&& P.status = "1"
			&& P.status_general = "1"
			&& U.status = "active"
			GROUP BY P.id DESC ', null , $this->_view->data[0]['id']
		   );

		   //<<<<----- ALL FAVORITE PAGE
		   $this->_view->postsFavs = $output->getPostsFavs(
		   'WHERE F.id_usr = '. $this->_view->data[0]['id'] .' ', null , $this->_view->data[0]['id']
		   );

			//<<<<<----- ALL Followers PAGE
		   $this->_view->_getFollowers = $output->getFollowers(
		   'WHERE F.following = '. $this->_view->data[0]['id'] .' ', null , $this->_view->data[0]['id']
		   );

		   //<<<<<----- ALL Followers PAGE
		   $this->_view->_getFollowing = $output->getFollowing(
		   'WHERE F.follower = '. $this->_view->data[0]['id'] .' ', null , $this->_view->data[0]['id']
		   );

		   //<--- INFO USER SESSION ACTIVE
		   $this->_view->infoSession  = $output->infoUser( $_SESSION['authenticated'] );

		 //<--- INFO USER ALL
		   $this->_view->info  = $output->infoUser( $this->_view->data[0]['id'] );

		   //<--- WHO TO FOLLOWER
		   $this->_view->whoToFollow  = $output->whoToFollow( $_SESSION['authenticated'] );

		   //<--- TRENDING TOPIC
		   $this->_view->trending     = $output->getTrendsTopic();

		   //<-- Follower -> Following
		   $this->_view->followActive = $output->checkFollow( $this->_view->data[0]['id'],  $_SESSION['authenticated']);

		   //<-- Following -> Follower
		   $this->_view->followingActive = $output->checkFollow( $_SESSION['authenticated'], $this->_view->data[0]['id'] );

		   //<--- Show Last Photos
		   $this->_view->lastPhotosVideos = $output->getPhotosVideos( $this->_view->data[0]['id'] );

			$this->_view->checkBlock  = $output->checkUserBlock( $_SESSION['authenticated'], $this->_view->data[0]['id'] );

			$this->_view->checkBlocked  = $output->checkUserBlock( $this->_view->data[0]['id'], $_SESSION['authenticated'] );

			//<<<--- * File Ajax * --->>>
			$this->_view->_file  = 'get_followers.php';

		 }//<--- IF COUNT != 0

		 /* Show Views */
        //cusads
        $this->_view->addRight = $output->getAds('right');
        $this->_view->addleft = $output->getAds('left');
         $this->_view->render('profile', null );
    }

	public function following() {
        $output                  = $this->loadModel('User');
        //update profile
        if(isset($_POST)){
            $this->updateProfile($_POST,$output);

            //update avatar
            if ($_FILES["pAvatar"]["error"] > 0) {
            } else {
                move_uploaded_file($_FILES["pAvatar"]["tmp_name"],
                    "public/avatar/" . $_FILES["pAvatar"]["name"]);
                $output->updateProfileAvatar(array('avatar'=>$_FILES["pAvatar"]["name"],'id'=>$_POST['pId']));
            }
            //end update avatar
            if(isset($_POST['pPass']) && $_POST['pPass'] != ''){
                $output->updateProfilePassword(array('id'=>$_POST['pId'],'password'=>$_POST['pPass']));
            }
        }
        //end update profile
        $this->_view->category = $output->getAllCategory();
        $this->_view->data       = $output->getUserId( $_GET['usr'] );
		$this->_view->settings   = $output->getSettings();
		$this->_view->notiMsg    = $output->notificationsMessages();
		$this->_view->notiIntera = $output->notificationsInteractions();
		$this->_view->_count     = count( $this->_view->data );
		$this->_view->pagesGeneral = $output->getAllPagesGeneral();
		$this->_view->getCountryUser = $output->getCountryUser( $this->_view->data[0]['id'] );
        $this->_view->countVote = $output->countVote($this->_view->data[0]['id']);
		//<---- Data User
		if( $this->_view->_count != 0 ) {
			$this->_view->title = $_SESSION['LANG']['following'].' - '.stripslashes( $this->_view->data[0]['name'] )." @".$this->_view->data[0]['username']." ";
			$this->_view->titleH4 = $_SESSION['LANG']['following'];

			//<----- ALL POST INDEX PAGE
		   $this->_view->posts = $output->getAllPosts(
		   'WHERE P.user = '.$this->_view->data[0]['id'].'
			&& P.status = "1"
			&& P.status_general = "1"
			&& U.status = "active"
			GROUP BY P.id DESC ', null , $this->_view->data[0]['id']
		   );

		   //<<<<----- ALL FAVORITE PAGE
		   $this->_view->postsFavs = $output->getPostsFavs(
		   'WHERE F.id_usr = '. $this->_view->data[0]['id'] .' ', null , $this->_view->data[0]['id']
		   );

			//<<<<<----- ALL Followers PAGE
		   $this->_view->_getFollowers = $output->getFollowers(
		   'WHERE F.following = '. $this->_view->data[0]['id'] .' ', null , $this->_view->data[0]['id']
		   );

		   //<<<<<----- ALL Followers PAGE
		   $this->_view->_getFollowing = $output->getFollowing(
		   'WHERE F.follower = '. $this->_view->data[0]['id'] .' ', null , $this->_view->data[0]['id']
		   );

		   //<--- INFO USER SESSION ACTIVE
		   $this->_view->infoSession  = $output->infoUser( $_SESSION['authenticated'] );

		 //<--- INFO USER ALL
		   $this->_view->info  = $output->infoUser( $this->_view->data[0]['id'] );

		   //<--- WHO TO FOLLOWER
		   $this->_view->whoToFollow  = $output->whoToFollow( $_SESSION['authenticated'] );

		   //<--- TRENDING TOPIC
		   $this->_view->trending     = $output->getTrendsTopic();

		   //<-- Follower -> Following
		   $this->_view->followActive = $output->checkFollow( $this->_view->data[0]['id'],  $_SESSION['authenticated']);

		   //<-- Following -> Follower
		   $this->_view->followingActive = $output->checkFollow( $_SESSION['authenticated'], $this->_view->data[0]['id'] );

		   $this->_view->checkBlock  = $output->checkUserBlock( $_SESSION['authenticated'], $this->_view->data[0]['id'] );

		   $this->_view->checkBlocked  = $output->checkUserBlock( $this->_view->data[0]['id'], $_SESSION['authenticated'] );

		   //<--- Show Last Photos
		   $this->_view->lastPhotosVideos = $output->getPhotosVideos( $this->_view->data[0]['id'] );

			//<<<--- * File Ajax * --->>>
			$this->_view->_file  = 'get_following.php';

		 }//<--- IF COUNT != 0

		 //<-- Render
        //cusads
        $this->_view->addRight = $output->getAds('right');
        $this->_view->addleft = $output->getAds('left');
         $this->_view->render('profile', null );
    }

	public function media() {
		$output                  = $this->loadModel('User');
        $this->_view->data       = $output->getUserId( $_GET['usr'] );
		$this->_view->settings   = $output->getSettings();
		$this->_view->notiMsg    = $output->notificationsMessages();
		$this->_view->notiIntera = $output->notificationsInteractions();
		$this->_view->_count     = count( $this->_view->data );
		$this->_view->pagesGeneral = $output->getAllPagesGeneral();

		//<---- Data User
		if( $this->_view->_count != 0 ) {
			$this->_view->title = $_SESSION['LANG']['media'].' - '.stripslashes( $this->_view->data[0]['name'] )." @".$this->_view->data[0]['username']." ";

			//<--- INFO USER SESSION ACTIVE
		   $this->_view->infoSession  = $output->infoUser( $_SESSION['authenticated'] );

		 //<--- INFO USER ALL
		   $this->_view->info  = $output->infoUser( $this->_view->data[0]['id'] );

		   //<--- WHO TO FOLLOWER
		   $this->_view->whoToFollow  = $output->whoToFollow( $_SESSION['authenticated'] );

		   $this->_view->checkBlock  = $output->checkUserBlock( $_SESSION['authenticated'], $this->_view->data[0]['id'] );

		   $this->_view->checkBlocked  = $output->checkUserBlock( $this->_view->data[0]['id'], $_SESSION['authenticated'] );

		   //<--- TRENDING TOPIC
		   $this->_view->trending     = $output->getTrendsTopic();

			//<--- Show Last Photos
		   $this->_view->_media = $output->getAllMedia( $this->_view->data[0]['id'], null, null );

		}

		 /* Show Views */
         $this->_view->render('media', null );
	}

	public function status() {
		 $output                       = $this->loadModel('User');
    	 $this->_view->data            = $output->getStatus( $_GET['usr'], $_GET['id_status'] );
		 $this->_view->followingActive = $output->checkFollow( $_SESSION['authenticated'] , $this->_view->data->user_id);
		 $this->_view->favorites       = $output->getFavorites( $_GET['id_status'] );
		 $this->_view->reply           = $output->getReply( $_GET['id_status'] );
		 $this->_view->countReply      = count( $this->_view->reply );
		 $this->_view->notiMsg         = $output->notificationsMessages();
		 $this->_view->notiIntera      = $output->notificationsInteractions();
		 $this->_view->checkBlock      = $output->checkUserBlock( $_SESSION['authenticated'], $this->_view->data->user_id );
		 $this->_view->activeRepost    = $output->checkRepost( $_GET['id_status'], $_SESSION['authenticated'] );
		 $this->_view->countRepost     = $output->getRepostUser( $_GET['id_status'] );
		 $this->_view->checkBlocked    = $output->checkUserBlock( $this->_view->data->user_id, $_SESSION['authenticated'] );
		 $this->_view->pagesGeneral = $output->getAllPagesGeneral();

		 //<--- INFO USER SESSION ACTIVE
		   $this->_view->infoSession  = $output->infoUser( $_SESSION['authenticated'] );

		 $chars = mb_strlen( $this->_view->data->post_details, 'utf8' );
		 if( $chars > 20 ) {
		 	$post_details = _Function::cropString( $this->_view->data->post_details, 20 )." // ";
		 } else if( $this->_view->data->post_details == '' ) {
		 	$post_details = null;
		 } else {
			 $post_details = $this->_view->data->post_details." // ";
		 }

		 $this->_view->title = $_SESSION['LANG']['status'].' - '.$post_details.stripslashes( $this->_view->data->name )." @".$this->_view->data->username." ";
        $dt =  $this->_view->data;

        $this->_view->post_meta_array = $output->get_post_meta($_GET['id_status']);

        $this->_view->getMedia       = $output->getMedia( $_GET['id_status'],$dt->token_id );
        $this->_view->votersCount = count($output->getVoter($_GET['id_status']));

        $this->_view->count_answer = $output->gettanswerCount($_GET['id_status']);
        $this->_view->countFavorite = $output->favoriteCount($_GET['id_status']);
        $this->_view->countReply = $output->countReply($_GET['id_status']);

		/* Show Views */
         $this->_view->render('status', null );
	}


    public function postadd(){
        if( Session::get( 'authenticated' ) ) {
            $output                   = $this->loadModel('User');
            $this->_view->settings    = $output->getSettings();
            $this->_view->notiMsg     = $output->notificationsMessages();
            $this->_view->notiIntera  = $output->notificationsInteractions();
            $this->_view->pagesGeneral = $output->getAllPagesGeneral();
            $this->_view->category = $output->getAllCategory();

            $this->_view->addRight = $output->getAds('right');
            $this->_view->addleft = $output->getAds('left');

            //<--- INFO USER SESSION
            $this->_view->infoSession = $output->infoUser( $_SESSION['authenticated'] );

            //<----- ALL POST INDEX PAGE
            $this->_view->posts = $output->getAllPosts( '
		   WHERE P.user = '.$_SESSION['authenticated'] .' && P.status = "1"
			&& U.status = "active" || P.user
			IN (
					SELECT following FROM followers WHERE follower = "'.$_SESSION['authenticated'] .'"
					&& status = "1"
			 ) && P.status = "1" && U.status = "active"
			 GROUP BY IF( P.`repost_of_id` = 0, P.`id`, P.`repost_of_id`) DESC',
                null ,
                $_SESSION['authenticated']
            );
            //<--- WHO TO FOLLOWER
            $this->_view->whoToFollow  = $output->whoToFollow( $_SESSION['authenticated'] );
            //<--- TRENDING TOPIC
            $this->_view->trending     = $output->getTrendsTopic();

        }

        if( !Session::get( 'authenticated' ) ) {
            $output = $this->loadModel('User');
            $this->_view->pagesGeneral = $output->getAllPagesGeneral();
            if( isset( $_GET['validate'] ) ) {
                $this->_view->accountValidate = $output->getCodeAccount( $_GET['validate'] ) ? 1 : 0;
            }

            if( $this->_view->accountValidate == 1 ) {
                $this->_view->actived = $output->activeAccount( $_GET['validate'] );
            }
        }
        /* Show Views */
        $this->_view->render( 'postadd', null );
    }

    public function  opinions(){


    }
    public function signup(){
        if( !Session::get( 'authenticated' ) ) {
            $output = $this->loadModel('User');
            $this->_view->pagesGeneral = $output->getAllPagesGeneral();

            if( isset( $_GET['validate'] ) ) {
                $this->_view->accountValidate = $output->getCodeAccount( $_GET['validate'] ) ? 1 : 0;
            }

            if( $this->_view->accountValidate == 1 ) {
                $this->_view->actived = $output->activeAccount( $_GET['validate'] );
            }

        }


        /* Show Views */
        $this->_view->render( 'signup', null );
    }


    public function changeUser(){
        if(isset($_SESSION['fb_redirect'])){


        if( !Session::get( 'authenticated' ) ) {
            $output = $this->loadModel('User');
            $this->_view->pagesGeneral = $output->getAllPagesGeneral();
            $this->_view->userArg = $output->getAllUserName();
            if( isset( $_GET['validate'] ) ) {
                $this->_view->accountValidate = $output->getCodeAccount( $_GET['validate'] ) ? 1 : 0;
            }

            if( $this->_view->accountValidate == 1 ) {
                $this->_view->actived = $output->activeAccount( $_GET['validate'] );
            }
        }
        $this->_view->render( 'changeUser', null );
        }else{
            header("Location:".URL_BASE);
        }
    }


    private function updateProfile($data,$output){
        $dataInfo = array(
            'id' => $data['pId'],
            'name' => $data['pName'],
            'sex' => $data['pSex'],
            'birth' => strtotime($data['pBirth']),
        );
        //$output = $this->loadModel('User');
        $output->updateProfile($dataInfo);

    }

    public function  updateUserProfile(){
        $output                  = $this->loadModel('User');
        //update profile
        if(isset($_POST)){
            $this->updateProfile($_POST,$output);

            //update avatar
            if ($_FILES["pAvatar"]["error"] > 0) {
            } else {
                move_uploaded_file($_FILES["pAvatar"]["tmp_name"],
                    "public/avatar/" . $_FILES["pAvatar"]["name"]);
                $output->updateProfileAvatar(array('avatar'=>$_FILES["pAvatar"]["name"],'id'=>$_POST['pId']));
            }
            //end update avatar
            if(isset($_POST['pPass']) && $_POST['pPass'] != ''){
                $output->updateProfilePassword(array('id'=>$_POST['pId'],'password'=>$_POST['pPass']));
            }
        }
        //end update profile
        $this->_view->category = $output->getAllCategory();
        $this->_view->settings   = $output->getSettings();
        $this->_view->data       = $output->getUserId( $_GET['usr'] );
        $this->_view->notiMsg    = $output->notificationsMessages();
        $this->_view->notiIntera = $output->notificationsInteractions();
        $this->_view->_count     = count( $this->_view->data );
        $this->_view->pagesGeneral = $output->getAllPagesGeneral();
        $this->_view->getCountryUser = $output->getCountryUser( $this->_view->data[0]['id'] );
        $this->_view->countVote = $output->countVote($this->_view->data[0]['id']);
        //<---- Data User
        if( $this->_view->_count != 0 ) {
            $this->_view->title = stripslashes( $this->_view->data[0]['name'] )." @".$this->_view->data[0]['username']." ";
            $this->_view->titleH4 =  'Update Profile';

            //<----- ALL POST INDEX PAGE
            $this->_view->posts = $output->getAllPosts(
                'WHERE P.user = '.$this->_view->data[0]['id'].'
			&& P.status = "1"
			&& P.status_general = "1"
			&& U.status = "active"
			GROUP BY P.id DESC', null , $this->_view->data[0]['id']
            );

            //<<<<<----- ALL Followers PAGE
            $this->_view->_getFollowers = $output->getFollowers(
                'WHERE F.following = '. $this->_view->data[0]['id'] .' ', null , $this->_view->data[0]['id']
            );

            //<----- ALL POST FAVORITE PAGE
            $this->_view->postsFavs = $output->getPostsFavs(
                'WHERE F.id_usr = '. $this->_view->data[0]['id'] .' ', null , null
            );

            //<<<<<----- ALL Followers PAGE
            $this->_view->_getFollowing = $output->getFollowing(
                'WHERE F.follower = '. $this->_view->data[0]['id'] .' ', null , $this->_view->data[0]['id']
            );
            //<--- INFO USER SESSION ACTIVE
            $this->_view->infoSession  = $output->infoUser( $_SESSION['authenticated'] );

            //<--- INFO USER ALL
            $this->_view->info  = $output->infoUser( $this->_view->data[0]['id'] );

            //<--- WHO TO FOLLOWER
            $this->_view->whoToFollow  = $output->whoToFollow( $_SESSION['authenticated'] );

            //<--- TRENDING TOPIC
            $this->_view->trending     = $output->getTrendsTopic();

            //<-- Follower -> Following
            $this->_view->followActive = $output->checkFollow( $this->_view->data[0]['id'],  $_SESSION['authenticated']);

            //<-- Following -> Follower
            $this->_view->followingActive = $output->checkFollow( $_SESSION['authenticated'], $this->_view->data[0]['id'] );

            //<--- Show Last Photos
            $this->_view->lastPhotosVideos = $output->getPhotosVideos( $this->_view->data[0]['id'] );

            $this->_view->checkBlock  = $output->checkUserBlock( $_SESSION['authenticated'], $this->_view->data[0]['id'] );

            $this->_view->checkBlocked  = $output->checkUserBlock( $this->_view->data[0]['id'], $_SESSION['authenticated'] );

            //<<<--- * File Ajax * --->>>
            $this->_view->_file  = 'get_posts.php';

        }//<--- IF COUNT != 0

        /* Show Views */
        //cusads
        $this->_view->addRight = $output->getAds('right');
        $this->_view->addleft = $output->getAds('left');
        $this->_view->render('update', null );
    }

    public function userVote() {

        $output                  = $this->loadModel('User');
        //update profile
        if(isset($_POST)){
            $this->updateProfile($_POST,$output);

            //update avatar
            if ($_FILES["pAvatar"]["error"] > 0) {
            } else {
                move_uploaded_file($_FILES["pAvatar"]["tmp_name"],
                    "public/avatar/" . $_FILES["pAvatar"]["name"]);
                $output->updateProfileAvatar(array('avatar'=>$_FILES["pAvatar"]["name"],'id'=>$_POST['pId']));
            }
            //end update avatar
            if(isset($_POST['pPass']) && $_POST['pPass'] != ''){
                $output->updateProfilePassword(array('id'=>$_POST['pId'],'password'=>$_POST['pPass']));
            }
        }
        //end update profile
        $this->_view->category = $output->getAllCategory();
        $this->_view->settings   = $output->getSettings();
        $this->_view->data       = $output->getUserId( $_GET['usr'] );
        $this->_view->notiMsg    = $output->notificationsMessages();
        $this->_view->notiIntera = $output->notificationsInteractions();
        $this->_view->_count     = count( $this->_view->data );
        $this->_view->pagesGeneral = $output->getAllPagesGeneral();
        $this->_view->getCountryUser = $output->getCountryUser( $this->_view->data[0]['id'] );
        $this->_view->countVote = $output->countVote($this->_view->data[0]['id']);
        //<---- Data User
        if( $this->_view->_count != 0 ) {
            $this->_view->title = stripslashes( $this->_view->data[0]['name'] )." @".$this->_view->data[0]['username']." ";
            $this->_view->titleH4 =  'Posts Voted';

            //<----- ALL POST INDEX PAGE
            $this->_view->posts = $output->getAllPosts(
                'WHERE P.user = '.$this->_view->data[0]['id'].'
			&& P.status = "1"
			&& P.status_general = "1"
			&& U.status = "active"
			GROUP BY P.id DESC', null , $this->_view->data[0]['id']
            );

            //<<<<<----- ALL Followers PAGE
            $this->_view->_getFollowers = $output->getFollowers(
                'WHERE F.following = '. $this->_view->data[0]['id'] .' ', null , $this->_view->data[0]['id']
            );

            //<----- ALL POST FAVORITE PAGE
            $this->_view->postsFavs = $output->getPostsFavs(
                'WHERE F.id_usr = '. $this->_view->data[0]['id'] .' ', null , null
            );

            //<<<<<----- ALL Followers PAGE
            $this->_view->_getFollowing = $output->getFollowing(
                'WHERE F.follower = '. $this->_view->data[0]['id'] .' ', null , $this->_view->data[0]['id']
            );
            //<--- INFO USER SESSION ACTIVE
            $this->_view->infoSession  = $output->infoUser( $_SESSION['authenticated'] );

            //<--- INFO USER ALL
            $this->_view->info  = $output->infoUser( $this->_view->data[0]['id'] );

            //<--- WHO TO FOLLOWER
            $this->_view->whoToFollow  = $output->whoToFollow( $_SESSION['authenticated'] );

            //<--- TRENDING TOPIC
            $this->_view->trending     = $output->getTrendsTopic();

            //<-- Follower -> Following
            $this->_view->followActive = $output->checkFollow( $this->_view->data[0]['id'],  $_SESSION['authenticated']);

            //<-- Following -> Follower
            $this->_view->followingActive = $output->checkFollow( $_SESSION['authenticated'], $this->_view->data[0]['id'] );

            //<--- Show Last Photos
            $this->_view->lastPhotosVideos = $output->getPhotosVideos( $this->_view->data[0]['id'] );

            $this->_view->checkBlock  = $output->checkUserBlock( $_SESSION['authenticated'], $this->_view->data[0]['id'] );

            $this->_view->checkBlocked  = $output->checkUserBlock( $this->_view->data[0]['id'], $_SESSION['authenticated'] );

            //<<<--- * File Ajax * --->>>
            $this->_view->_file  = 'get_posts_vote.php';

        }//<--- IF COUNT != 0

        /* Show Views */
        //cusads
        $this->_view->addRight = $output->getAds('right');
        $this->_view->addleft = $output->getAds('left');
        $this->_view->render('profile', null );
    }
}
?>